home *** CD-ROM | disk | FTP | other *** search
/ MacFormat UK 179 / MF_UK_179_1.iso / DiscContents / In the mag / Widgets / PEMDAS 1.0 / PEMDAS / PEMDAS.wdgt / numberClasses.js < prev    next >
Encoding:
Text File  |  2006-12-12  |  1.8 KB  |  82 lines

  1.  
  2. function PDAnswer (number)
  3. {
  4. this.master=number;
  5. this.flo=formatAnswerForLocale(formatAnswerForDisplay(number, 1));
  6. this.sci=formatAnswerForLocale(formatAnswerForDisplay(number, 2));
  7. this.eng=formatAnswerForLocale(formatAnswerForDisplay(number, 3));
  8. this.bin=(Math.floor(number)).toString(2);
  9. this.oct=(Math.floor(number)).toString(8);
  10. this.hex=(Math.floor(number)).toString(16);
  11. var self = this;
  12. this.getAnswer=function(type)
  13. {
  14. switch(type) {
  15. case 1:
  16. if (preferencesPrecision) {
  17. return formatAnswerForLocale(formatAnswerForDisplay(formatWithGlobalPrecision(this.master)));
  18. } else 
  19. return this.flo;
  20. break;
  21. case 2:
  22. if (preferencesPrecision) {
  23. return formatAnswerForLocale(formatAnswerForDisplay(formatWithGlobalPrecision(this.master)));
  24. } else 
  25. return this.sci;
  26. break;
  27. case 3:
  28. if (preferencesPrecision) {
  29. return formatAnswerForLocale(formatAnswerForDisplay(formatWithGlobalPrecision(this.master)));
  30. } else 
  31. return this.eng;
  32. break;
  33. case 4:
  34. return formatAnswerForLocale(formatPercentNumber(formatAnswerForDisplay(formatWithGlobalPrecision(100*this.master), 1)));
  35. break;
  36. case 5:
  37. return formatBinaryNumber(this.bin);
  38. break;
  39. case 6:
  40. return formatOctNumber(this.oct);
  41. break;
  42. case 7:
  43. return formatHexNumber(this.hex);
  44. break;
  45. }
  46. return 'error';
  47. }
  48. this.reformatNumbers=function()
  49. {
  50. this.flo=formatAnswerForLocale(formatAnswerForDisplay(this.master, 1));
  51. }
  52. }
  53. function PDNumber()
  54. {
  55. this.masterNumber=false;
  56. this.superMasterNumber=false;
  57. this.number=false;
  58. var self=this;
  59. if (arguments.length) {
  60. this.masterNumber=arguments[0];
  61. this.number=parseFloat(arguments[0]);
  62. if (isNaN(this.number))
  63. this.number=false;
  64. }
  65. this.getNumber=function() 
  66. {
  67. return this.number;
  68. }
  69. this.getMasterNumber=function() 
  70. {
  71. return this.masterNumber;
  72. }
  73. this.setMasterNumber=function(newNumber) 
  74. {
  75. self.masterNumber=parseFloat(newNumber);
  76. }
  77. this.initWithNumber=function(numberToInitWith) 
  78. {
  79. this.number=numberToInitWith;
  80. }
  81. }
  82.